package cn.dengqiang.user.controller;

import cn.dengqiang.basic.exception.BusinessException;
import cn.dengqiang.basic.util.AjaxResult;
import cn.dengqiang.user.service.IVerifyCodeserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeserService verifyCodeserService;

    @PostMapping("/smsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> params){
        String phone = params.get("phone");
        try {
            verifyCodeserService.sendSmsCode(params);
            return AjaxResult.me();
        }
        catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setMessage("发送失败!"+e.getMessage());
        }
        catch (Exception e) {
            return AjaxResult.me().setMessage("系统错误!"+e.getMessage());
        }
    }
}
